Skip to content

Reimplement strtod and parseFloat / strtod + Fix String.fromCodePoint + improve strtol #768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 74 commits into from
Sep 15, 2019
Merged

Conversation

MaxGraey
Copy link
Member

@MaxGraey MaxGraey commented Aug 17, 2019

  • Improve precision and parsing for parseFloat / strtod;
  • Fix String.fromCharCode;
  • Minor improvements for parseInt / strtol.

DONE

@MaxGraey MaxGraey requested a review from dcodeIO September 5, 2019 08:58
@MaxGraey
Copy link
Member Author

MaxGraey commented Sep 5, 2019

@dcodeIO I also added some tests from tc39/test262 and found one issue. Plz don't merge this yet

@MaxGraey
Copy link
Member Author

MaxGraey commented Sep 5, 2019

Ok. Now should be more right. I switched to approach for handling Pow10 as in RapidJSON with division on significand / pow10(-exp) when exp is negative instead multiply it to negative power from LUT. This approach don't loose precision in some rare cases.

cc @dcodeIO
plz review it again)

@MaxGraey
Copy link
Member Author

MaxGraey commented Sep 6, 2019

It ready to re-review

@MaxGraey MaxGraey requested a review from dcodeIO September 6, 2019 11:14
@dcodeIO
Copy link
Member

dcodeIO commented Sep 6, 2019

Regarding these failure cases: How bad is this practically? Are these merely edge cases? What do other standard libraries do?

@MaxGraey
Copy link
Member Author

MaxGraey commented Sep 6, 2019

It has only corner cases for extremely large or small values. To improve this cases we should choose much more complex solution which I'll definitely implement later. But this solution is pretty enought for most cases. See this comment. And this affect only when x < ~1e-22 || x >= ~1e40. We have potentially wrong 2 last decimal digits

@dcodeIO
Copy link
Member

dcodeIO commented Sep 6, 2019

I see, thanks. So this is due to limiting to 64 bits for intermediate values, right? If so, tempted to say that this might be as good as it gets at this point in time anyway, since emulating 128 bit floats without multi-value looks like it'd need a shadow stack / heap support anyway. Even if metallic did that with structs, we'd probably still want to use multi-value (2 x 64 bits passed via the execution stack).

@MaxGraey
Copy link
Member Author

MaxGraey commented Sep 6, 2019

128-bit soft floats usually slower than 128-bit fixed points. So 128-bit modular algos much better and use for such cases pretty widely for double <-> string conversion and trig argument reduction (Payne Hanek approach for large arguments). But in case with double <-> string probably BigFloat128 better solution

@MaxGraey
Copy link
Member Author

MaxGraey commented Sep 6, 2019

@dcodeIO Currently it's not absolutely ideal. I'll rewrite part for handling huge values but this require some refactoring because dtoa also based on same BigFloat routines so will be great unify all of this and the same time fix some mispricisions on dtoa. But could be done later I guess.

@dcodeIO dcodeIO merged commit c165ee5 into AssemblyScript:master Sep 15, 2019
@dcodeIO
Copy link
Member

dcodeIO commented Sep 15, 2019

Thanks!

@MaxGraey MaxGraey deleted the improve-strtod branch September 15, 2019 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants